<template>
	<view class="search-container" :style="{'background-color': bgColor, 'padding': `${marginNum} 0`}">
		<view class="search-content" :style="{'margin': `0 ${marginNum}`}">
			<image class="search-icon left" src="../../static/image/common/search.png" mode=""></image>
			<view class="input-content" @click="actionSearch">
				<u--input @blur="search" :disabled="disabled" class="search-input" fontSize="26rpx" :placeholder="placeholder" border="none"
					v-model="searchTxt">
				</u--input>
			</view>
			<image v-if="filter" class="search-icon right" src="../../static/image/common/filter.png" mode="" @click="openFilter"></image>
		</view>
	</view>
</template>

<script>
	export default{
		props: {
			value: String,
			placeholder: {
				type: String,
				default: () => '请输入搜索条件'
			},
			filter: {
				type: Boolean,
				default: () => false
			},
			disabled: {
				type: Boolean,
				default: () => false
			},
			bgColor: {
				type: String,
				default: '#fff'
			},
			marginNum: {
				type: String,
				default: '24rpx'
			}
		},
		data(){
			return {
				searchTxt: ''
			}
		},
		methods: {
			openFilter(){
				let _self = this
				_self.$emit('open-filter')
			},
			search(){
				let _self = this
				_self.$emit('input', _self.searchTxt)
				_self.$emit('search')
			},
			actionSearch(){
				let _self = this
				if(!_self.disabled) return
				_self.$emit('search-click')
			},
		},
	}
</script>

<style lang='scss' scoped>
	.search-container{
		background: #fff;
		padding: 20rpx 0;
		.search-content{
			background: #fff;
			margin: 0 24rpx;
			padding: 15rpx 20rpx;
			border-radius: 39rpx;
			border: 2rpx solid #F7F7F7;
			position: relative;
			.search-icon{
				position: absolute;
				top: 50%;
				transform: translateY(-50%);
				&.left{
					width: 29rpx;
					height: 35rpx;
					left: 33rpx;
				}
				&.right{
					width: 30rpx;
					height: 32rpx;
					right: 33rpx;
				}
			}
		}
		.input-content{
			margin: 0 60rpx;
		}
	}
</style>